Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Add CMake build #3621

Draft
wants to merge 183 commits into
base: main
Choose a base branch
from
Draft

build: Add CMake build #3621

wants to merge 183 commits into from

Conversation

HuidaeCho
Copy link
Member

@HuidaeCho HuidaeCho commented Apr 18, 2024

This PR replaces #3021. Branched from https://github.com/nilason/grass/tree/cmake_build_work. Thanks @nilason!

Current status: I can compile the entire gisbase using CMake 3.29.1 and GCC 13.2.0. Running grass directly from build/gisbase works fine.

Windows Tests

For my records, message from message(WIN32=${WIN32}, MSVC=${MSVC}, MSYS=${MSYS}, MINGW=${MINGW}) on Windows (all from cmd in ssh):

CMake variables:

TODOs

  • Windows
  • macOS
  • locale
  • addon support
  • ...

Documentation

@Mahesh1998 and I are testing, fixing, and documenting this PR on Ubuntu. https://github.com/Mahesh1998/grass-docs/blob/main/cmake_build_docs/

Building on Slackware with Conda packages

Install Miniconda

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod a+x Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh -b -u -p ~/usr/local/opt/miniconda
~/usr/local/opt/miniconda/bin/conda init
. ~/.bashrc
conda config --add channels conda-forge
conda config --set channel_priority strict

Create a new environment and install libraries

conda create -n grass
conda activate grass
conda install proj libgdal fftw blas libpdal wxpython

Build GRASS

mkdir build
cd build
# ignore warnings about runtime path (Conda libraries will be picked over system libraries)
cmake .. -DCMAKE_PREFIX_PATH=$HOME/usr/local/opt/miniconda/envs/grass
make -j`nproc`

Run GRASS

./output/bin/grass

rkanavath and others added 30 commits June 6, 2023 09:40
author Rashad Kanavath <[email protected]> 1497210739 +0200
committer Markus Neteler <[email protected]> 1669989265 +0100

parent 464ffca
author Rashad Kanavath <[email protected]> 1497210739 +0200
committer Markus Neteler <[email protected]> 1669989193 +0100

parent 464ffca
author Rashad Kanavath <[email protected]> 1497210739 +0200
committer Markus Neteler <[email protected]> 1669989189 +0100

parent 464ffca
author Rashad Kanavath <[email protected]> 1497210739 +0200
committer Markus Neteler <[email protected]> 1669989180 +0100

parent 464ffca
author Rashad Kanavath <[email protected]> 1497210739 +0200
committer Markus Neteler <[email protected]> 1669988019 +0100

parent 464ffca
author Rashad Kanavath <[email protected]> 1497210739 +0200
committer Markus Neteler <[email protected]> 1669987997 +0100

parent 464ffca
author Rashad Kanavath <[email protected]> 1497210739 +0200
committer Markus Neteler <[email protected]> 1669987899 +0100

parent 464ffca
author Rashad Kanavath <[email protected]> 1497210739 +0200
committer Markus Neteler <[email protected]> 1669986420 +0100

parent 464ffca
author Rashad Kanavath <[email protected]> 1497210739 +0200
committer Markus Neteler <[email protected]> 1669986410 +0100

parent 464ffca
author Rashad Kanavath <[email protected]> 1497210739 +0200
committer Markus Neteler <[email protected]> 1669985337 +0100

parent 464ffca
author Rashad Kanavath <[email protected]> 1497210739 +0200
committer Markus Neteler <[email protected]> 1669984062 +0100

parent 464ffca
author Rashad Kanavath <[email protected]> 1497210739 +0200
committer Markus Neteler <[email protected]> 1669984050 +0100

parent 464ffca
author Rashad Kanavath <[email protected]> 1497210739 +0200
committer Markus Neteler <[email protected]> 1669984037 +0100

parent 464ffca
author Rashad Kanavath <[email protected]> 1497210739 +0200
committer Markus Neteler <[email protected]> 1669984013 +0100

inital work on grass cmake build

wip: cmake fixes

add find iconv script

fix blas error wrong target added

link with dl lib on linux

disable some modules (wip)

search whatever is fftw's inlcude dir

driver lib depends on iconv

fftw in required package

build fftw modules

add python libs

test with py3

install sqlfiles to etc/sql

install lock, clean_temp, echo to ./etc/

install libs

link with dl lib

cleanup cmake code

fix python script & lib install dirs

fixed gisbase for grass startup script

install modules to bin

add PNG as dependency to r.out.png

install __init__.py

wrong install dir for python api

install with rpath to avoid LD_LIBRARY_PATH

whitespace fixes

MSVC: check for _WIN32 to use msvc and mingw32

MSVC: disable some programs temporarily

update cmake scripts to manage thirdparty libs

disable X11 on windows

update generation of config.h

fix list of cmake depends

msvc compile fixes

use INIFINITY rather than gcc only division by zero

ignore visual studio, cmake files

use INFINITY rather than divide by zero

use _WIN32 for mingw32 and msvc

add ssize_t for msvc

msvc add _USE_MATH_DEFINES an d export dll

keep check for long long int in cache

include driver/init.c when building display drivers

use _WIN32 to build msvc and mingw32

update cmake for lib/db

link with libm only on unix

msvc: skip chmod on windows msvc

use INFINITY rather than diivide by zero

add msvc specific headers: unistd.h, dirent.h

grass moved to git... So follow that in cmake.

fix check for HAVE_LONG_LONG

include math.h only on msvc. To be discussed

void* arithmetic (GCC extension) is not allowed in msvc

disable d.mon, d.font on msvc. TBD

missing O_ACCMODE on msvc

Add unistd.h on windows

Source copied from http://stackoverflow.com/a/826027

dbmi_base: add dirent.h and dirent.c for msvc

use macro INFINITY rather than GCC divide by zero

MSVC: fix missing strings.h

use math defines on msvc

update find package of fftw

added required defines into parent scope

update setting of HAVE_* defines. 1/n

use cmake target check if possible

add odbc target on windows

update values in generated config.h

reorganize cmake option defaults, cmake flags, macros

cmake c and cxx flags include _CRT_SECURE_NO_WARNINGS to avoid a lot msdn warnings
check_target macro is a helper to reduce number of lines in include/CMakeLists.txt

simlib: min, max are already available

Find which C standard library does not provide them
And if there is one, see if grass support that compiler/platform combination
To be discussed

CMake: reorganize cmake functions, macros, find_scripts (Like a Pro)

make_script_in_dir is renamed to build_script_in_subdir

I still don't the naming of macro is clear.
One without knowledge of CMake, AutoMake or any
other build scripting  experience must be able to deduct
what is the macro/functions.

Even if there will be a header comment with 'PURPOSE' field.

fix define used in lib/rst/interp_float

fix tools/timer build

add gettimeofday windowss implemenation from postgresql

CMake: reorganize cmake functions (2)

MSVC: copy UINT64CONST(x) from postgresql

WIP: disable pyc generation with g.parser on msvc

fix ccmath complex struct for msvc

take out GCC'sim and stick to C standard

copy external/ccmath/ccmath.h to include/grass/ccmath_grass.h

CMake: enable cmake export all symbols on for shared libs

CMake: build lib/python on MSVC

fix ctypesgen.cmake
reorg cmake functions used by python
add new cmake function to copy_python_files and compile

MSVC: include sys/time.h if available or time.h

CMake: remove debug trace

CMake: minor cleanup

CMake: make gui/images

CMake: fix run_grass of locale_strings and ctypesgen

CMake: link with postgres is optional

gid_t, uid_t, pid_t exists on *nix

use find_library_suffix to switch between debug and rest

avoid touch  .stamp files and depend on generated pyc file

CMake: update definiition of HAVE_PROJ_H

include winsock.h only on msvc

CMake: remove annoying logs

for fix TODO for g.version

CMake: depend on pyc file not on a new .stamp file

CMake: fix syntax error

CMake: fix sqlite include dir variable

CMake: detect version of proj4 before activating defines

MSVC: avoid pulling min max on windows

CMake: update list of enabled modules

TODO r.watershed, fix cmake proj4 library varname

Revert "simlib: min, max are already available"

This reverts commit ab2b961.

CMake: update proj library variables (remove suffix 4)

use macro INFINITY

MSVC: fix gisinit initialized flag

export initialized using dllexport when building.
export macros has been generated by CMake's GenerateExportHeader.
cmake calls this for all libraries in build_module function.

There is a change in initialized variable decl on msvc and rest of compilers.
This point has to be discussed with other devs

MSVC: fix min, max macro stuff

update TODO, list of modules not built by cmake

CMake: update find scripts to find debug then release

update list of options.
WITH_PYTHON addded to build python bindings (default is OFF)

CMake: zlib is check with cmake target

demolocation is configured in lib/init/CMakeLists.txt

CMake: generate grass.py and grass.sh scripts (build tree)

CMake: fix startup script generation (install tree)

fix generation of startup scripts

fix g.list building 1/2

MSVC: missing regex, use PCRE (wip)

lib/init: fix startup script on linux

fix input configure_file

activate building g.remove on msvc

add cmake messages for lib/init/

include sys/time.h if not on msvc.

As we don't include grass/config.h we cannot simply check against
HAVE_SYS_TIME_H

install proj data files

geotiff_csv only required in windows

check this with devs

wip: add compile defs via interface library

fix g.version, grass_gproj with proj6

create startup shell scripts in bin

fix startup script

MSVC: configure run_grass.bat, run_python.bat

generate html docs

fix copy_python_file (used in gui/wxpython, lib/python)

build all gui/wxpython modules

wrapper scripts to build html docs

skip html-description for g.parser

update msvc target properties

fix install directory for running from binary tree

install tools for buildtree and installtree

fix build docs using cmake POST_BUILD

update mkhtml.py for cmake

copy header to binary directory using add_custom_command

install extra files in lib/gis using post_build

add copy_header as depdendency to grass_datetime

first install tools directory

find cairo debug and then release libs

add POST_BUILD target for documentation only if WITH_DOCS

build gui/wxpython, fix html description generation

MSVC: uninitialized variable

CMake: update to work with autoconf and cmake

CMake: install et copy gui/images gui/icons

CMake: fix grass version date

CMake: fix building gui (python files, docs, html)

fix dist include dir name

build docs only if requested

fix typo

fix cmake syntax errors

cmake linux fixes

check for _WIN32 define to work with msvc

fix newline at end of file

WIP: update helper cmake scripts

update copy_header target

use gisbase as dist directory for build tree

cmake: fix build for db/drivers

ignore __pycache__ directory when scanning for .py files

wip: use a gisbase as dist directory

WIP: temporary fix for find_library output variable

CMake: move wxpython cmake codes to gui/wxpython

raise ScriptError

wip wip build docs

minor cleanup

install html docs for driver db

update building html docs (wip)

add missing dependencies for v.lrs

update building python modules (wip)

use target property to check if running python script (docs)

cleanup cmake helper functions (exe, libs, python, docs)

copy strings.h and unistd.h on msvc

python files (target) depend only grass.script if building docs

fix build docs for windows and linux (wip)

seperate list of g.gui.* modules

try to make generic build docs (wip)

build docs html for not win32 (wip)

fix cmake syntax error

update pgm extension for running html description

remove temp files after docs are finished

CMake: fix IN_LIST syntax

ficx cmake syntax error

fix again linux html description for python with a main script

wip: include from config build is breaking msvc

msvc: disable db drivers (wip)

add test.raster3d.lib into NO_HTML_DESCR_TARGETS

CMake: missing endif()

x extension on running html descr

copy r.in.wms directory to etc/

fix building py modules

add grass dll directory to path windows grass.bat

debug linux build failures

cmake missing endif

set main script file only for those selected modules

cmake: fix python docs for linux and windows

create scripts directory in gisbase

cmake debug message

add missing include

add cmake find scripts for liblas, netcdf, postgresql

update proj4 detection to support 4.x, 5.x , 6.x versions

update cmake functions to build grass modules

add proj4 version defines (support 5.x+)

add options for v.in.dwg and liblas modules

activate build of modules deactivated

detecting of new 3rdd party libraries

fix i.landsat.acca on msvc

add dll export macro for iostream, dspf, calc

fix r.terraflow on msvc

use _WIN32 rather than __MINGW32__ for msvc

use infinity macro to build on msvc

missing include on msvc

copy VERSIONUMBER and license to gisbase/etc

support for multiple proj4 version

update building lib/python (except ctypes)

use INFINITY macro to work with msvc

fix building gui/wxpython/xml

use approach with cmake env command for cross platform build

void* arithmetic is not allowed in msvc

To be discussed

copy __init__.py for python/grass/

fix wrong cmake varible used

copy init py to etc/python/grass/

db/drviers: odbc, sqlite, dbf,  ogr, postgresql

check for PQCmdTuples in postgresql

add defines to be posix conformat on msvc

bring in testing using ctest (wip)

improve proj4 detection

Signed-off-by: Rashad Kanavath <[email protected]>

keep proj4 version string in cache (very useful later)

find optional packages quietly

use PRIMARY_DEPENDS option in build_module

generate wxpython menu xml stuff after building all executables

ogsf and nviz depends on grass_raster

update gui/wxpython build

add missing modules to build

missing v.clip

install html file is exists

cmake cleanup

reorder dependencies of gui/wxpython modules

avoid breakage in autconf build

missing file copy

fix mkhtml doc building, exe, lib, python, gui

fix find scripts on windows

fix always out of date for custom targets

fix missing optional dependds to grass gis library

fix missing math.h include

wrong path used under cmake binary directory

keep autoconf build  conflict with cmake

.bat files must be in scripts/

fix installation of gui/images, gui/icons

Revert "install html file is exists"

This reverts commit 9e83f6f.

Apply suggestions from code review

trivial changes (comment style) applied

moved tools/ -> utils/

sync to main

sync to main

fix indentation

remove trailing white space

remove trailing white space

revert C related INFINITY/NAN changes (taken care of in OSGeo#2681)
Attempt to add a CI workflow
Co-authored-by: Edouard Choinière <[email protected]>
Co-authored-by: Edouard Choinière <[email protected]>
Co-authored-by: Edouard Choinière <[email protected]>
Co-authored-by: Edouard Choinière <[email protected]>
Co-authored-by: Edouard Choinière <[email protected]>
Co-authored-by: Edouard Choinière <[email protected]>
Co-authored-by: Edouard Choinière <[email protected]>
Co-authored-by: Edouard Choinière <[email protected]>
Co-authored-by: Edouard Choinière <[email protected]>
@HuidaeCho
Copy link
Member Author

It's really nice to see this real collaborative effort all on one PR. Many different authors all for one same goal.

Yes, this is really great!

@echoix
Copy link
Member

echoix commented Jul 18, 2024

Resolved one conflict manually

@HuidaeCho
Copy link
Member Author

Resolved one conflict manually

Thanks!

Fixed Building grass with Ubuntu System Libraries and cmake
@echoix
Copy link
Member

echoix commented Jul 29, 2024

Once #4101 is merged (soon), there will be a new configure flag in the header files to integrate.

msvc/gettimeofday.c Outdated Show resolved Hide resolved
msvc/gettimeofday.c Show resolved Hide resolved
msvc/gettimeofday.c Outdated Show resolved Hide resolved
msvc/gettimeofday.c Outdated Show resolved Hide resolved
msvc/gettimeofday.c Outdated Show resolved Hide resolved
msvc/gettimeofday.c Outdated Show resolved Hide resolved
msvc/gettimeofday.c Outdated Show resolved Hide resolved
msvc/gettimeofday.c Outdated Show resolved Hide resolved
@HuidaeCho
Copy link
Member Author

msvc/gettimeofday.c is copied from https://github.com/postgres/postgres/blob/master/src/port/win32gettimeofday.c based on the commit log of the original PR: add gettimeofday windowss implemenation from postgresql. I assume we can use this file in GRASS because their license is BSD or MIT-like (more permissive than GPL). If that's not the case, there is another version from StackOverflow and we may be able to use it, but I'm not a copyright expert.

@lbartoletti
Copy link
Contributor

I assume we can use this file in GRASS because their license is BSD or MIT-like

Yes, you can re use it.

@echoix
Copy link
Member

echoix commented Nov 8, 2024

Changes from using lapacke.h haven't been included here yet. Soon we might have to make sure everything parson works after changing some common r.colors.out code and v.colours.out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Related code is in C C++ Related code is in C++ CI Continuous integration database Related to database management display docs general GUI wxGUI related imagery libraries misc module Python Related code is in Python raster Related to raster data processing raster3d temporal Related to temporal data processing translation Message translation related vector Related to vector data processing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants